import pygame

class Sound:
    def __init__(self):
        #We could run as many as two sounds at once, so we have two sound keyStrings
        self.keyString = ""
        self.keyString2 = ""

    #Sets the sound to be played first.  
    def setSound(self, string):
        self.keyString = string
        self.keyString2 = ""

    #Sets the sound to be played second.  
    def setSound2(self, string):
        self.keyString2 = string

    #We play both sounds simultaneous.  With a little modification, this can play them sequentially
    #But that slows down gameplay
    def run(self):
        #See if the file exists.  If we get an error loading it, try loading a default sound
        #If there is no default sound, then report back.
        if(self.keyString != "" and self.keyString != " "):
            try:
                sound = pygame.mixer.Sound("%s.wav" % self.keyString)
                sound.play()
            except pygame.error, message:
                try:
                    sound = pygame.mixer.Sound("default.wav")
                    sound.play()
                except pygame.error, message:
                    print "Cannot load sound: %s.wav" % self.keyString    
    
        if(self.keyString2 != "" and self.keyString2 != " "):
            try:
                sound = pygame.mixer.Sound("%s.wav" % self.keyString2)
                sound.play()
            except pygame.error, message:
                try:
                    sound = pygame.mixer.Sound("default.wav")
                    sound.play()
                except pygame.error, message:
                    print "Cannot load sound: %s.wav" % self.keyString2
                    
    def quit(self):        
        pygame.quit()


    